/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package probando;



/**
 *
 * @author VWV
 */
public class RunWithJoin implements Runnable{
    private UiPrincipal view = null;
    private boolean consola = false;

    public RunWithJoin(UiPrincipal view, boolean consola){

        if (view!=null) {
            this.view = view;
            this.consola = consola;
        } else {
            System.exit(1);
        }

    }

    public RunWithJoin(){

    }

    public void run() {
        if (consola)
           System.out.println("\n----\n");
        
        view.limpiarOutput();

        Thread moe = new Thread(new Contador(view,"Moe",10,500,consola));
        Thread larry = new Thread(new Contador(view,"Larry",10,500,consola));
        Thread curly = new Thread(new Contador(view,"Curly",10,500,consola));

        moe.start();

        try {
            moe.join();
        } catch (InterruptedException ex) {
            System.out.println("Join interrumpido (del runner) ");
        }

        larry.start();

        try {
            larry.join();
        } catch (InterruptedException ex) {
            System.out.println("Join interrumpido (del runner) ");
        }

        curly.start();

        try {
            curly.join();
        } catch (InterruptedException ex) {
            System.out.println("Join interrumpido (del runner) ");
        }finally{
            view.restablecerVentana();
        }
        
    }

}
